﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WEB.Core.Controls;
using Ext.Net;
using WEB.Core.Util;
using log4net;
using WEB.BLL.Services;
using WEB.BLL.Entities;
using WEB.BLL;

namespace WEB.APP.Modules.List
{
    public partial class ListClient : BasePage 
    {
        public ListClient()
            : base(SCREENS.LISTCLIENT, false)
        {

        }

        protected override void Page_Load(object sender, EventArgs e)
        {
            hdScreenDetailID.Value = SCREENS.CLIENTDETAIL;
            base.Page_Load(sender, e);
            mnEdit.Text = "View Detail";
        }

        void WindowEditor_SaveClick(object sender, EventArgs e)
        {
            this.storeMain.DataBind();
        }
        protected void storeMain_OnRefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            ClientEntity _ett = new ClientEntity()
            {
                Start = Util.Obj2Int(e.Parameters["start"]),
                Keyword = txtKeyword.Text.Trim()
            };
            _ett.EndNum = Util.Obj2Int(e.Parameters["limit"]) + _ett.Start;

            IList<ClientEntity> _lst = ClientService.GetInstance().Find(_ett);

            if (null != _lst)
            {
                this.storeMain.DataSource = _lst;
                this.storeMain.DataBind();
                e.Total = _ett.TotalRow;
            }
        }

        [DirectMethod]
        public void Delete(decimal ID)
        {
            try
            {
                if (ID > 0)
                {
                    ClientService.GetInstance().Delete(new ClientEntity() { ClientId = ID });
                    Notification("Delete Completed !!!");
                }
            }
            catch (Exception ex)
            {
                Notification(ex);
            }
        }
    }
}
